package com.mojavelinux.open18;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.Min;
import org.hibernate.validator.NotNull;

// TODO: could consider doing category
@Entity
@Table( name = "star_rating", uniqueConstraints = @UniqueConstraint( columnNames = { "course_id", "voter" } ) )
public class StarRating implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private long id;
	
	private Course course;
	
	private String voter;
	
	private int grade;
	
	private Date timestamp;

	public StarRating() {}
	
	public StarRating( int grade, String voter ) {
		this.grade = grade;
		this.voter = voter;
		this.timestamp = new Date();
	}
	
	@Id
	@GeneratedValue( strategy = GenerationType.AUTO )
	@Column( name = "id" )
	@NotNull
	public long getId() {
		return id;
	}

	public void setId( long id ) {
		this.id = id;
	}
	
	@ManyToOne
	public Course getCourse() {
		return course;
	}

	public void setCourse( Course course ) {
		this.course = course;
	}

	@Column( name = "grade" )
	@Min( 0 )
	public int getGrade() {
		return grade;
	}

	public void setGrade( int rating ) {
		this.grade = rating;
	}

	@Column( name = "voter" )
	@NotNull
	public String getVoter() {
		return voter;
	}

	public void setVoter( String voter ) {
		this.voter = voter;
	}

	@Column( name = "timestamp" )
	@NotNull
	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp( Date timestamp ) {
		this.timestamp = timestamp;
	}
	
}
